package com.demo.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.demo.dao.ShortUrlMapper;
import com.demo.service.ShortUrlService;

@Service
public class ShortUrlServiceImpl implements ShortUrlService{
	
	@Autowired
	private ShortUrlMapper shortUrlMapper ;

	@Override
	public void addShortUrl(Map map) {
		this.shortUrlMapper.insertShortUrl(map);
	}

	@Override
	@Cacheable("ShortUrlMapper.selectLongUrl") //表示其返回值将被加入缓存。同时在查询时，会先从缓存中获取，若不存在才再发起对数据库的访问
	public String queryLongUrl(String shortKey) {
		return this.shortUrlMapper.selectLongUrl(shortKey) ;
	}

}
